package com.hgnu.dorm.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.util.SaResult;
import com.hgnu.dorm.domain.dto.DormitoryPageQueryDto;
import com.hgnu.dorm.domain.po.Dormitory;
import com.hgnu.dorm.domain.po.PageBean;
import com.hgnu.dorm.domain.po.Result;
import com.hgnu.dorm.service.DormitoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/dormitory")
@Tag(name = "宿舍管理接口")
public class DormitoryController {
    @Autowired
    private DormitoryService dormitoryService;
    //宿舍分页查询
    @GetMapping
    @Operation(summary = "获取宿舍列表接口")
    @SaCheckPermission("dorm.select")
    public SaResult list(DormitoryPageQueryDto dto){
        PageBean page = dormitoryService.page(dto);
        return SaResult.data(page);
    }

    /**
     * 获取宿舍信息详细信息
     */
    @GetMapping(value = "/{id}")
    @Operation(summary = "根据id获取单个宿舍信息")
    @SaCheckPermission("dorm.select")
    public SaResult getInfo(@PathVariable("id") Integer id)
    {
        return SaResult.data(dormitoryService.selectDormitoryById(id));
    }

    /**
     * 新增宿舍信息
     */
    @PostMapping
    @Operation(summary = "新增宿舍接口")
    @SaCheckPermission("dorm.add")
    public SaResult add(@RequestBody Dormitory dormitory)
    {
        return SaResult.data(dormitoryService.insertDormitory(dormitory));
    }

    /**
     * 修改宿舍信息
     */
    @PutMapping
    @Operation(summary = "修改宿舍接口")
    @SaCheckPermission("dorm.update")
    public SaResult edit(@RequestBody Dormitory dormitory)
    {
        return SaResult.data(dormitoryService.updateDormitory(dormitory));
    }

    /**
     * 删除宿舍信息
     */

    @DeleteMapping("/{ids}")
    @Operation(summary = "根据多个id删除宿舍")
    @SaCheckPermission("dorm.delete")
    public SaResult remove(@PathVariable Long[] ids)
    {
        return SaResult.data(dormitoryService.deleteDormitoryByIds(ids));
    }

    /**
     * 获取可选择宿舍楼信息
     */
    @GetMapping("/select")
    @Operation(summary = "获取可选择宿舍楼信息")
    @SaCheckPermission("dorm.select")
    public Result select(){
        return Result.success(dormitoryService.select());
    }
}
